<!DOCTYPE html>
<html lang="zh-CN" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>QGIS开发教程 | QGIS使用教程</title>
    <meta name="description" content="QGIS使用教程，从入门到进阶">
    <meta name="generator" content="VitePress v1.0.0-rc.31">
    <link rel="preload stylesheet" href="/qgis-cookbook/assets/style.ldbbiKxJ.css" as="style">
    
    <script type="module" src="/qgis-cookbook/assets/app.D1mhV-Tp.js"></script>
    <link rel="preload" href="/qgis-cookbook/assets/inter-roman-latin.bvIUbFQP.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/qgis-cookbook/assets/chunks/framework.QWNq-BiV.js">
    <link rel="modulepreload" href="/qgis-cookbook/assets/chunks/theme.omG1qQ_s.js">
    <link rel="modulepreload" href="/qgis-cookbook/assets/chunks/PagePreview.skys-joc.js">
    <link rel="modulepreload" href="/qgis-cookbook/assets/docs_senior_dev.md.-JHOtOsV.lean.js">
    <link rel="icon" href="/logo.png">
    <link rel="stylesheet" href="/lib/fancybox.css">
    <script src="/lib/fancybox.umd.js"></script>
    <script id="check-dark-mode">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"auto",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
    <script id="check-mac-os">document.documentElement.classList.toggle("mac",/Mac|iPhone|iPod|iPad/i.test(navigator.platform));</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-669ac9bc><!--[--><!--]--><!--[--><span tabindex="-1" data-v-94825da3></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-94825da3> Skip to content </a><!--]--><!----><header class="VPNav" data-v-669ac9bc data-v-de454cd3><div class="VPNavBar has-sidebar" data-v-de454cd3 data-v-e57c26a8><div class="container" data-v-e57c26a8><div class="title" data-v-e57c26a8><div class="VPNavBarTitle has-sidebar" data-v-e57c26a8 data-v-c66c7bb7><a class="title" href="/qgis-cookbook/" data-v-c66c7bb7><!--[--><!--]--><!--[--><img class="VPImage logo" src="/qgis-cookbook/logo.png" alt data-v-cde49352><!--]--><!--[-->QGIS使用教程<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-e57c26a8><div class="curtain" data-v-e57c26a8></div><div class="content-body" data-v-e57c26a8><!--[--><!--]--><div class="VPNavBarSearch search" data-v-e57c26a8><!----></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-e57c26a8 data-v-bcdd47af><span id="main-nav-aria-label" class="visually-hidden" data-v-bcdd47af>Main Navigation</span><!--[--><!--[--><a class="VPLink link vp-external-link-icon VPNavBarMenuLink" href="https://lzugis15.gitee.io/qgis-cookbook/img/GIS基础.pdf" target="_blank" rel="noreferrer" tabindex="0" data-v-bcdd47af data-v-14cc87c3><!--[--><span data-v-14cc87c3>GIS基础</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/qgis-cookbook/docs/basic/" tabindex="0" data-v-bcdd47af data-v-14cc87c3><!--[--><span data-v-14cc87c3>QGIS基础操作</span><!--]--></a><!--]--><!--[--><a class="VPLink link VPNavBarMenuLink" href="/qgis-cookbook/docs/senior/toolbox.html" tabindex="0" data-v-bcdd47af data-v-14cc87c3><!--[--><span data-v-14cc87c3>QGIS进阶操作</span><!--]--></a><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-e57c26a8 data-v-616b8f7f><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-616b8f7f data-v-0385fa2c data-v-0c9a1e26><span class="check" data-v-0c9a1e26><span class="icon" data-v-0c9a1e26><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-0385fa2c><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-0385fa2c><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-e57c26a8 data-v-7b5f925f data-v-feb74dec><!--[--><a class="VPSocialLink no-icon" href="https://lzugis.cn/" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1685841853530" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3800" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><path d="M352.814545 385.396364m-33.512727 0a33.512727 33.512727 0 1 0 67.025455 0 33.512727 33.512727 0 1 0-67.025455 0Z" fill="#50B674" p-id="3801"></path><path d="M502.690909 384.465455m-33.512727 0a33.512727 33.512727 0 1 0 67.025454 0 33.512727 33.512727 0 1 0-67.025454 0Z" fill="#50B674" p-id="3802"></path><path d="M576.232727 534.341818m-23.272727 0a23.272727 23.272727 0 1 0 46.545455 0 23.272727 23.272727 0 1 0-46.545455 0Z" fill="#50B674" p-id="3803"></path><path d="M694.458182 536.203636m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" fill="#50B674" p-id="3804"></path><path d="M512 0C229.003636 0 0 229.003636 0 512s229.003636 512 512 512 512-229.003636 512-512S794.996364 0 512 0z m-87.505455 630.225455c-26.996364 0-48.407273-5.585455-75.403636-11.17091l-75.403636 37.236364 21.410909-64.232727c-53.992727-37.236364-85.643636-85.643636-85.643637-145.221818 0-102.4 96.814545-182.458182 215.04-182.458182 105.192727 0 198.283636 64.232727 216.901819 150.807273-6.516364-0.930909-13.963636-0.930909-20.48-0.93091-102.4 0-182.458182 76.334545-182.458182 170.356364 0 15.825455 2.792727 30.72 6.516363 44.683636-7.447273 0-13.963636 0.930909-20.48 0.93091z m314.647273 75.403636l15.825455 53.992727-58.647273-32.581818c-21.410909 5.585455-42.821818 11.170909-64.232727 11.170909-102.4 0-182.458182-69.818182-182.458182-155.461818s80.058182-155.461818 182.458182-155.461818c96.814545 0 182.458182 69.818182 182.458182 155.461818 0 47.476364-31.650909 90.298182-75.403637 122.88z" fill="#50B674" p-id="3805"></path></svg></a><a class="VPSocialLink no-icon" href="https://gitee.com/lzugis15" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1671270284061" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1920" width="64" height="64"><path d="M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512z m259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z" fill="#C71D23" p-id="1921"></path></svg></a><a class="VPSocialLink no-icon" href="https://blog.csdn.net/GISShiXiSheng" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1671270414569" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2135" width="64" height="64"><path d="M512 0c282.784 0 512 229.216 512 512s-229.216 512-512 512S0 794.784 0 512 229.216 0 512 0z m189.952 752l11.2-108.224c-31.904 9.536-100.928 16.128-147.712 16.128-134.464 0-205.728-47.296-195.328-146.304 11.584-110.688 113.152-145.696 232.64-145.696 54.784 0 122.432 8.8 151.296 18.336L768 272.704C724.544 262.24 678.272 256 599.584 256c-203.2 0-388.704 94.88-406.4 263.488C178.336 660.96 303.584 768 535.616 768c80.672 0 138.464-6.432 166.336-16z" fill="#CE000D" p-id="2136"></path></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-e57c26a8 data-v-3a44bf07 data-v-6c022edf><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-6c022edf><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-6c022edf><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-6c022edf><div class="VPMenu" data-v-6c022edf data-v-6b7639ff><!----><!--[--><!--[--><!----><div class="group" data-v-3a44bf07><div class="item appearance" data-v-3a44bf07><p class="label" data-v-3a44bf07>Appearance</p><div class="appearance-action" data-v-3a44bf07><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="Switch to dark theme" aria-checked="false" data-v-3a44bf07 data-v-0385fa2c data-v-0c9a1e26><span class="check" data-v-0c9a1e26><span class="icon" data-v-0c9a1e26><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-0385fa2c><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-0385fa2c><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><div class="group" data-v-3a44bf07><div class="item social-links" data-v-3a44bf07><div class="VPSocialLinks social-links-list" data-v-3a44bf07 data-v-feb74dec><!--[--><a class="VPSocialLink no-icon" href="https://lzugis.cn/" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1685841853530" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3800" xmlns:xlink="http://www.w3.org/1999/xlink" width="48" height="48"><path d="M352.814545 385.396364m-33.512727 0a33.512727 33.512727 0 1 0 67.025455 0 33.512727 33.512727 0 1 0-67.025455 0Z" fill="#50B674" p-id="3801"></path><path d="M502.690909 384.465455m-33.512727 0a33.512727 33.512727 0 1 0 67.025454 0 33.512727 33.512727 0 1 0-67.025454 0Z" fill="#50B674" p-id="3802"></path><path d="M576.232727 534.341818m-23.272727 0a23.272727 23.272727 0 1 0 46.545455 0 23.272727 23.272727 0 1 0-46.545455 0Z" fill="#50B674" p-id="3803"></path><path d="M694.458182 536.203636m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z" fill="#50B674" p-id="3804"></path><path d="M512 0C229.003636 0 0 229.003636 0 512s229.003636 512 512 512 512-229.003636 512-512S794.996364 0 512 0z m-87.505455 630.225455c-26.996364 0-48.407273-5.585455-75.403636-11.17091l-75.403636 37.236364 21.410909-64.232727c-53.992727-37.236364-85.643636-85.643636-85.643637-145.221818 0-102.4 96.814545-182.458182 215.04-182.458182 105.192727 0 198.283636 64.232727 216.901819 150.807273-6.516364-0.930909-13.963636-0.930909-20.48-0.93091-102.4 0-182.458182 76.334545-182.458182 170.356364 0 15.825455 2.792727 30.72 6.516363 44.683636-7.447273 0-13.963636 0.930909-20.48 0.93091z m314.647273 75.403636l15.825455 53.992727-58.647273-32.581818c-21.410909 5.585455-42.821818 11.170909-64.232727 11.170909-102.4 0-182.458182-69.818182-182.458182-155.461818s80.058182-155.461818 182.458182-155.461818c96.814545 0 182.458182 69.818182 182.458182 155.461818 0 47.476364-31.650909 90.298182-75.403637 122.88z" fill="#50B674" p-id="3805"></path></svg></a><a class="VPSocialLink no-icon" href="https://gitee.com/lzugis15" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1671270284061" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1920" width="64" height="64"><path d="M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512z m259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z" fill="#C71D23" p-id="1921"></path></svg></a><a class="VPSocialLink no-icon" href="https://blog.csdn.net/GISShiXiSheng" aria-label target="_blank" rel="noopener" data-v-feb74dec data-v-9e5de970><svg t="1671270414569" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2135" width="64" height="64"><path d="M512 0c282.784 0 512 229.216 512 512s-229.216 512-512 512S0 794.784 0 512 229.216 0 512 0z m189.952 752l11.2-108.224c-31.904 9.536-100.928 16.128-147.712 16.128-134.464 0-205.728-47.296-195.328-146.304 11.584-110.688 113.152-145.696 232.64-145.696 54.784 0 122.432 8.8 151.296 18.336L768 272.704C724.544 262.24 678.272 256 599.584 256c-203.2 0-388.704 94.88-406.4 263.488C178.336 660.96 303.584 768 535.616 768c80.672 0 138.464-6.432 166.336-16z" fill="#CE000D" p-id="2136"></path></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-e57c26a8 data-v-80adf601><span class="container" data-v-80adf601><span class="top" data-v-80adf601></span><span class="middle" data-v-80adf601></span><span class="bottom" data-v-80adf601></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav reached-top" data-v-669ac9bc data-v-b240202e><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-b240202e><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-b240202e><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-b240202e>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-b240202e data-v-e4cc878c><button data-v-e4cc878c>Return to top</button><!----></div></div><aside class="VPSidebar" data-v-669ac9bc data-v-f726f66c><div class="curtain" data-v-f726f66c></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-f726f66c><span class="visually-hidden" id="sidebar-aria-label" data-v-f726f66c> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-f726f66c><section class="VPSidebarItem level-0 has-active" data-v-f726f66c data-v-b2ec8f7a><!----><div class="items" data-v-b2ec8f7a><!--[--><div class="VPSidebarItem level-1 is-link" data-v-b2ec8f7a data-v-b2ec8f7a><div class="item" data-v-b2ec8f7a><div class="indicator" data-v-b2ec8f7a></div><a class="VPLink link link" href="/qgis-cookbook/docs/senior/toolbox.html" data-v-b2ec8f7a><!--[--><p class="text" data-v-b2ec8f7a>1. 工具箱使用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b2ec8f7a data-v-b2ec8f7a><div class="item" data-v-b2ec8f7a><div class="indicator" data-v-b2ec8f7a></div><a class="VPLink link link" href="/qgis-cookbook/docs/senior/model.html" data-v-b2ec8f7a><!--[--><p class="text" data-v-b2ec8f7a>2. 空间建模</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-b2ec8f7a data-v-b2ec8f7a><div class="item" data-v-b2ec8f7a><div class="indicator" data-v-b2ec8f7a></div><a class="VPLink link link" href="/qgis-cookbook/docs/senior/dev.html" data-v-b2ec8f7a><!--[--><p class="text" data-v-b2ec8f7a>3. QGIS二次开发</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-669ac9bc data-v-d9887676><div class="VPDoc has-sidebar has-aside" data-v-d9887676 data-v-bb05d22a><!--[--><!--]--><div class="container" data-v-bb05d22a><div class="aside" data-v-bb05d22a><div class="aside-curtain" data-v-bb05d22a></div><div class="aside-container" data-v-bb05d22a><div class="aside-content" data-v-bb05d22a><div class="VPDocAside" data-v-bb05d22a data-v-18d9846e><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" role="navigation" data-v-18d9846e data-v-3863ff2a><div class="content" data-v-3863ff2a><div class="outline-marker" data-v-3863ff2a></div><div class="outline-title" role="heading" aria-level="2" data-v-3863ff2a>章节导航</div><nav aria-labelledby="doc-outline-aria-label" data-v-3863ff2a><span class="visually-hidden" id="doc-outline-aria-label" data-v-3863ff2a> Table of Contents for current page </span><ul class="root" data-v-3863ff2a data-v-57363d56><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-18d9846e></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-bb05d22a><div class="content-container" data-v-bb05d22a><!--[--><!--]--><!----><main class="main" data-v-bb05d22a><div style="position:relative;" class="vp-doc _qgis-cookbook_docs_senior_dev" data-v-bb05d22a><div><h1 id="qgis开发教程" tabindex="-1">QGIS开发教程 <a class="header-anchor" href="#qgis开发教程" aria-label="Permalink to &quot;QGIS开发教程&quot;">​</a></h1><div class="tip custom-block"><p class="custom-block-title">说明</p><p>QGIS二次开发的方式包括：Python命令行、代码编辑器和Python脚本等。</p></div><h2 id="一、python命令行" tabindex="-1">一、Python命令行 <a class="header-anchor" href="#一、python命令行" aria-label="Permalink to &quot;一、Python命令行&quot;">​</a></h2><p><img src="/qgis-cookbook/img/qgis/python-console.png" alt="Python命令行" data-fancybox="gallery"></p><p><code>Python Console</code>面板可分为：1.顶部工具栏；2.控制台；3.命令输入窗口。下面以调用<code>Buffer</code>为例，说明一下<code>Python Console</code>的使用。</p><h3 id="_1-查看帮助文档" tabindex="-1">1. 查看帮助文档 <a class="header-anchor" href="#_1-查看帮助文档" aria-label="Permalink to &quot;1. 查看帮助文档&quot;">​</a></h3><p>在顶部工具栏点击<code>Help</code>按钮，即可查看相关的帮助文档，相关的帮助文档有：</p><ul><li><strong>python_console</strong>: <a href="https://docs.qgis.org/3.16/en/docs/user_manual/plugins/python_console.html" target="_blank" rel="noreferrer">https://docs.qgis.org/3.16/en/docs/user_manual/plugins/python_console.html</a></li><li><strong>QGIS Python API</strong>：<a href="https://qgis.org/pyqgis/3.16/" target="_blank" rel="noreferrer">https://qgis.org/pyqgis/3.16/</a></li><li><strong>pyqgis_developer_cookbook</strong>：<a href="https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/index.html" target="_blank" rel="noreferrer">https://docs.qgis.org/3.16/en/docs/pyqgis_developer_cookbook/index.html</a></li></ul><h3 id="_1-引入依赖" tabindex="-1">1. 引入依赖 <a class="header-anchor" href="#_1-引入依赖" aria-label="Permalink to &quot;1. 引入依赖&quot;">​</a></h3><p>在命令行中使用<code>Processing</code>需要先输入代码<code>from qgis import processing</code>引入依赖。</p><h3 id="_2-查看所有可用工具" tabindex="-1">2. 查看所有可用工具 <a class="header-anchor" href="#_2-查看所有可用工具" aria-label="Permalink to &quot;2. 查看所有可用工具&quot;">​</a></h3><p>可在命令行中输入如下代码查看所有可用工具。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> alg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsApplication.processingRegistry().algorithms():</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(alg.id(), </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;-&gt;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, alg.displayName())</span></span></code></pre></div><p>运行后结果如下。</p><p><img src="/qgis-cookbook/img/qgis/list-tools.png" alt="list-tools" data-fancybox="gallery"></p><h3 id="_3-查看帮助" tabindex="-1">3. 查看帮助 <a class="header-anchor" href="#_3-查看帮助" aria-label="Permalink to &quot;3. 查看帮助&quot;">​</a></h3><p>在命令行中输入<code>processing.algorithmHelp(&quot;native:buffer&quot;)</code>可查看<code>Buffer</code>的详细帮助，输出内容如下。</p><div class="language-txt vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">txt</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span>This algorithm computes a buffer area for all the features in an input layer, using a fixed or dynamic distance.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The end cap style parameter controls how line endings are handled in the buffer.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The join style parameter specifies whether round, miter or beveled joins should be used when offsetting corners in a line.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>The miter limit parameter is only applicable for miter join styles, and controls the maximum distance from the offset curve to use when creating a mitered join.</span></span>
<span class="line"><span></span></span>
<span class="line"><span></span></span>
<span class="line"><span>----------------</span></span>
<span class="line"><span>Input parameters</span></span>
<span class="line"><span>----------------</span></span>
<span class="line"><span></span></span>
<span class="line"><span>INPUT: Input layer</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterFeatureSource</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- str: layer ID</span></span>
<span class="line"><span>		- str: layer name</span></span>
<span class="line"><span>		- str: layer source</span></span>
<span class="line"><span>		- QgsProcessingFeatureSourceDefinition</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span>		- QgsVectorLayer</span></span>
<span class="line"><span></span></span>
<span class="line"><span>DISTANCE: Distance</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterDistance</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- float</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>SEGMENTS: Segments</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	The segments parameter controls the number of line segments to use to approximate a quarter circle when creating rounded offsets.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterNumber</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- float</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>END_CAP_STYLE: End cap style</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterEnum</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Available values:</span></span>
<span class="line"><span>		- 0: Round</span></span>
<span class="line"><span>		- 1: Flat</span></span>
<span class="line"><span>		- 2: Square</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- str: as string representation of int, e.g. &#39;1&#39;</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>JOIN_STYLE: Join style</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterEnum</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Available values:</span></span>
<span class="line"><span>		- 0: Round</span></span>
<span class="line"><span>		- 1: Miter</span></span>
<span class="line"><span>		- 2: Bevel</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- str: as string representation of int, e.g. &#39;1&#39;</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>MITER_LIMIT: Miter limit</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterNumber</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- float</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>DISSOLVE: Dissolve result</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterBoolean</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- bool</span></span>
<span class="line"><span>		- int</span></span>
<span class="line"><span>		- str</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>OUTPUT: Buffered</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Parameter type:	QgsProcessingParameterFeatureSink</span></span>
<span class="line"><span></span></span>
<span class="line"><span>	Accepted data types:</span></span>
<span class="line"><span>		- str: destination vector file, e.g. &#39;d:/test.shp&#39;</span></span>
<span class="line"><span>		- str: &#39;memory:&#39; to store result in temporary memory layer</span></span>
<span class="line"><span>		- str: using vector provider ID prefix and destination URI, e.g. &#39;postgres:…&#39; to store result in PostGIS table</span></span>
<span class="line"><span>		- QgsProcessingOutputLayerDefinition</span></span>
<span class="line"><span>		- QgsProperty</span></span>
<span class="line"><span></span></span>
<span class="line"><span>----------------</span></span>
<span class="line"><span>Outputs</span></span>
<span class="line"><span>----------------</span></span>
<span class="line"><span></span></span>
<span class="line"><span>OUTPUT:  &lt;QgsProcessingOutputVectorLayer&gt;</span></span>
<span class="line"><span>	Buffered</span></span></code></pre></div><h3 id="_4-输入数据" tabindex="-1">4. 输入数据 <a class="header-anchor" href="#_4-输入数据" aria-label="Permalink to &quot;4. 输入数据&quot;">​</a></h3><p>在<code>Buffer</code>工具中，需要一个数据或者图层作为输入，我们可以通过如下方式指定输入数据。</p><ul><li>指定数据文件，<code>layer = &#39;D:/桌面/capital.geojson&#39;</code></li><li>界面中当前选择的图层，<code>layer = mc.currentLayer()</code></li><li>界面中的图层，<code>layer = mc.layer(0)</code></li></ul><p><strong>说明</strong>：<code>mc</code>的定义如下代码所示。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">mc </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> iface.mapCanvas()</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> lyr </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> mc.layers():</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(lyr.name())</span></span></code></pre></div><h3 id="_5-无界面运行" tabindex="-1">5. 无界面运行 <a class="header-anchor" href="#_5-无界面运行" aria-label="Permalink to &quot;5. 无界面运行&quot;">​</a></h3><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 计算缓冲区</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:buffer&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital-buffer.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span></code></pre></div><h3 id="_6-有界面运行" tabindex="-1">6. 有界面运行 <a class="header-anchor" href="#_6-有界面运行" aria-label="Permalink to &quot;6. 有界面运行&quot;">​</a></h3><p>可通过如下命令创建一个可交互的对话框，并打开对话框。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">my_dialog </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing.createAlgorithmDialog(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:buffer&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital-buffer.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">my_dialog.show()</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">;</span></span></code></pre></div><p><img src="/qgis-cookbook/img/qgis/buffer-dialog.png" alt="buffer-dialog" data-fancybox="gallery"></p><p>也可通过如下代码直接代开可交互的对话框。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 创建对话框并立即打开</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">processing.execAlgorithmDialog(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:buffer&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital-buffer.shp&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">;</span></span></code></pre></div><h2 id="二、代码编辑器" tabindex="-1">二、代码编辑器 <a class="header-anchor" href="#二、代码编辑器" aria-label="Permalink to &quot;二、代码编辑器&quot;">​</a></h2><p>点击<code>Python Console</code>工具栏<code>Show Editor</code>即可打开代码编辑器，如下图所示。 <img src="/qgis-cookbook/img/qgis/code-editor.png" alt="code-editor" data-fancybox="gallery"></p><p>代码编辑器界面分为顶部工具栏和代码编辑区域，在编辑器中可编辑脚本，编辑完成后，点击<code>Run</code>按钮即可运行。</p><h3 id="_1-查看图层属性" tabindex="-1">1. 查看图层属性 <a class="header-anchor" href="#_1-查看图层属性" aria-label="Permalink to &quot;1. 查看图层属性&quot;">​</a></h3><p>通过如下代码可打开数据并查看数据属性。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/layer-capital.shp&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">vlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsVectorLayer(path, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;layer-capital&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;ogr&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    </span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">for</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feature </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">in</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> vlayer.getFeatures():</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (feature[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;name&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">])</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;-----------------&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span></code></pre></div><p><img src="/qgis-cookbook/img/qgis/code1.png" alt="code1" data-fancybox="gallery"></p><h3 id="_2-多工具运行" tabindex="-1">2. 多工具运行 <a class="header-anchor" href="#_2-多工具运行" aria-label="Permalink to &quot;2. 多工具运行&quot;">​</a></h3><p>如下代码演示了如何运行多个工具。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 计算缓冲区并计算clip结果</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">input1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;layer-capital.shp&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">input2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;layer-college.shp&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">output1 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;capital-buffer.shp&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">output2 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;college-buffer.shp&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">output3 </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;clip-result.shp&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:buffer&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: input1, </span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: output1</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:buffer&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: input2, </span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: output2</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;native:clip&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, {</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: output1, </span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;OVERLAY&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: output2,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: output3</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">})</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;计算完成！&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span><span style="--shiki-light:#B31D28;--shiki-dark:#FDAEB7;--shiki-light-font-style:italic;--shiki-dark-font-style:italic;">;</span></span></code></pre></div><p><img src="/qgis-cookbook/img/qgis/run-result.png" alt="run-result" data-fancybox="gallery"></p><h3 id="_3-打开文件" tabindex="-1">3. 打开文件 <a class="header-anchor" href="#_3-打开文件" aria-label="Permalink to &quot;3. 打开文件&quot;">​</a></h3><p>如下代码演示了不同格式的文件的打开方式。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># 打开数据</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> os;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># get the path to the shapefile</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">path_to_airports_layer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;E:\my\qgis-lecture\data\layer-capital.shp&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">vlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsVectorLayer(path_to_airports_layer, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;layer-capital&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;ogr&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># get the path to the gpkg</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">path_to_gpkg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> os.path.join(QgsApplication.pkgDataPath(), </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;resources&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;data&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;world_map.gpkg&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># append the layername part</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">gpkg_countries_layer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> path_to_gpkg </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;|layername=countries&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">vlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> iface.addVectorLayer(gpkg_countries_layer , </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;countries&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;ogr&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># POSTGIS</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uri </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsDataSourceUri()</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># set host name, port, database name, username and password</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uri.setConnection(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;localhost&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;5432&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;dbname&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;johny&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;xxx&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># set database schema, table name, geometry column and optionally</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># subset (WHERE clause)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uri.setDataSource(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;public&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;roads&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;the_geom&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;cityid = 2643&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;primary_key_field&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">vlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsVectorLayer(uri.uri(</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">False</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">), </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;layer name you like&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;postgres&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># CSV</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">uri </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;file://</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">/testdata/delimited_xy.csv?delimiter=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&amp;xField=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&amp;yField=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">{}</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.format(os.getcwd(), </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;x&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;y&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">vlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsVectorLayer(uri, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;layer name you like&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;delimitedtext&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># raster</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">path_to_tif </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;qgis-projects/python_cookbook/data/srtm.tif&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsRasterLayer(path_to_tif, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;SRTM layer name&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> not</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> vlayer.isValid():</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Layer failed to load!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    QgsProject.instance().addMapLayer(vlayer)</span></span></code></pre></div><p>如下代码展示了如何打开tif。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;D:/lzugis23/proj/qgis培训/code/qgis-lecture/data/&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">path_to_tif </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> base_path </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">+</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;dem.tif&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rlayer </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsRasterLayer(path_to_tif, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;dem&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">if</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> not</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> rlayer.isValid():</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    print</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;Layer failed to load!&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">:</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    QgsProject.instance().addMapLayer(rlayer)</span></span></code></pre></div><p><img src="/qgis-cookbook/img/qgis/raster-file.png" alt="raster-file" data-fancybox="gallery"></p><h2 id="三、python脚本文件" tabindex="-1">三、Python脚本文件 <a class="header-anchor" href="#三、python脚本文件" aria-label="Permalink to &quot;三、Python脚本文件&quot;">​</a></h2><h3 id="_1-创建脚本" tabindex="-1">1. 创建脚本 <a class="header-anchor" href="#_1-创建脚本" aria-label="Permalink to &quot;1. 创建脚本&quot;">​</a></h3><p>在工具箱顶部，点击“Python脚本”按钮，点击<code>Create New Script...</code>可创建一个新的Python脚本文件，打开后弹出代码编辑界面。</p><p><img src="/qgis-cookbook/img/qgis/new-script.png" alt="new-script" data-fancybox="gallery"></p><p>点击<code>Create New Script from Template...</code>可创建一个新的Python脚本模板文件，打开后弹出代码编辑界面，编辑器中会自动填入一些初始化的脚本。</p><p><img src="/qgis-cookbook/img/qgis/new-script-template.png" alt="new-script-template" data-fancybox="gallery"></p><p>如下代码展示了在脚本中计算缓冲区并将结果栅格化。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis.PyQt.QtCore </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QCoreApplication</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis.core </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (QgsProcessing,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingAlgorithm,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingException,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingOutputNumber,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingParameterDistance,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingParameterFeatureSource,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingParameterVectorDestination,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                       QgsProcessingParameterRasterDestination)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">class</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> ExampleProcessingAlgorithm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">QgsProcessingAlgorithm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    This is an example algorithm that takes a vector layer,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    creates some new layers and returns some results.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &quot;&quot;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> tr</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, string):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns a translatable string with the self.tr() function.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QCoreApplication.translate(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;Processing&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, string)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> createInstance</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # Must return a new copy of your algorithm.</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ExampleProcessingAlgorithm()</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> name</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns the unique algorithm name.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;bufferrasterextend&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> displayName</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns the translated algorithm name.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲计算并栅格化结果&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> group</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns the name of the group this algorithm belongs to.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;My Script&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> groupId</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns the unique ID of the group this algorithm belongs</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        to.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;myscripts&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> shortHelpString</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Returns a localised short help string for the algorithm.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;先进行缓冲区计算，在将结果转换为栅格展示。&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> initAlgorithm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, config</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">None</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Here we define the inputs and outputs of the algorithm.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # &#39;INPUT&#39; is the recommended name for the main input</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # parameter.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingParameterFeatureSource(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输入矢量数据&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                types</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[QgsProcessing.TypeVectorAnyGeometry]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingParameterVectorDestination(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输出缓冲区计算结果&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # &#39;OUTPUT&#39; is the recommended name for the main output</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # parameter.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingParameterRasterDestination(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输出栅格文件&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingParameterDistance(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;BUFFERDIST&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲区半径&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                defaultValue</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # Make distance units match the INPUT layer units:</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                parentParameterName</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingParameterDistance(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;CELLSIZE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;单元格大小&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                defaultValue</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                parentParameterName</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">        self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addOutput(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            QgsProcessingOutputNumber(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">                self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;Number of features processed&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> processAlgorithm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, parameters, context, feedback):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        Here is where the processing itself takes place.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">        &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # First, we get the count of features from the INPUT layer.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # This layer is defined as a QgsProcessingParameterFeatureSource</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # parameter, so it is retrieved by calling</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # self.parameterAsSource.</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        input_featuresource </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.parameterAsSource(parameters,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                                     &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                                     context)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        numfeatures </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> input_featuresource.featureCount()</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # Retrieve the buffer distance and raster cell size numeric</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # values. Since these are numeric values, they are retrieved</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # using self.parameterAsDouble.</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        bufferdist </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.parameterAsDouble(parameters, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFERDIST&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                            context)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        rastercellsize </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.parameterAsDouble(parameters, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;CELLSIZE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                                context)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">            return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        buffer_result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing.run(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;native:buffer&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # Here we pass on the original parameter values of INPUT</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # and BUFFER_OUTPUT to the buffer algorithm.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: bufferdist,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            },</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # Because the buffer algorithm is being run as a step in</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # another larger algorithm, the is_child_algorithm option</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # should be set to True</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            is_child_algorithm</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            #</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # It&#39;s important to pass on the context and feedback objects to</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # child algorithms, so that they can properly give feedback to</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # users and handle cancelation requests.</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            context</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">context,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            feedback</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">feedback)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # Check for cancelation</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">            return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # Run the separate rasterization algorithm using the buffer result</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # as an input.</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        rasterized_result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing.run(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;qgis:rasterize&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            {</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # Here we pass the &#39;OUTPUT&#39; value from the buffer&#39;s result</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # dictionary off to the rasterize child algorithm.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;LAYER&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;EXTENT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;MAP_UNITS_PER_PIXEL&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: rastercellsize,</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">                # Use the original parameter value.</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">            },</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            is_child_algorithm</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            context</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">context,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            feedback</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">feedback)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">            return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">        # Return the results</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: rasterized_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                &#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: numfeatures}</span></span></code></pre></div><p>点击“Run”按钮，运行该算法，打开如下界面。</p><p><img src="/qgis-cookbook/img/qgis/run-script.png" alt="run-script" data-fancybox="gallery"></p><h3 id="_2-标准函数" tabindex="-1">2. 标准函数 <a class="header-anchor" href="#_2-标准函数" aria-label="Permalink to &quot;2. 标准函数&quot;">​</a></h3><p>如上代码所示，脚本中的标准函数及说明如下：</p><ul><li><strong>createInstance (必须)</strong></li></ul><p>如下图所示，必须返回一个算法新实例。如果更改了类的名称，请确保在此处返回的值与类名称匹配！</p><p><img src="/qgis-cookbook/img/qgis/create-instance.png" alt="create-instance" data-fancybox="gallery"></p><ul><li><strong>name (必须)</strong></li></ul><p>返回一个用来标识算法的名称。</p><ul><li><strong>displayName (必须)</strong></li></ul><p>如下图所示，返回在界面上展示的算法的名称。</p><p><img src="/qgis-cookbook/img/qgis/displayname.png" alt="displayname" data-fancybox="gallery"></p><ul><li><strong>group</strong></li></ul><p>如下图所示，返回该算法所属的组。</p><p><img src="/qgis-cookbook/img/qgis/group.png" alt="group" data-fancybox="gallery"></p><ul><li><strong>groupId</strong></li></ul><p>返回算法的唯一分组ID。</p><ul><li><strong>shortHelpString</strong></li></ul><p>返回算法的简单说明与操作帮助。</p><ul><li><strong>initAlgorithm (必须)</strong></li></ul><p>如下代码所示，在此处定义算法的输入与输出。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> initAlgorithm</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(self, config</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">None</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">):</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">    # &#39;INPUT&#39; is the recommended name for the main input</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">    # parameter.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingParameterFeatureSource(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输入矢量数据&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            types</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">[QgsProcessing.TypeVectorAnyGeometry]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingParameterVectorDestination(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输出缓冲区计算结果&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">    # &#39;OUTPUT&#39; is the recommended name for the main output</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">    # parameter.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingParameterRasterDestination(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输出栅格文件&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingParameterDistance(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;BUFFERDIST&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲区半径&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            defaultValue</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">            # Make distance units match the INPUT layer units:</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            parentParameterName</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addParameter(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingParameterDistance(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;CELLSIZE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;单元格大小&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">),</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            defaultValue</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> =</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">            parentParameterName</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">    self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.addOutput(</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        QgsProcessingOutputNumber(</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">            self</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">.tr(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;Number of features processed&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">        )</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    )</span></span></code></pre></div><ul><li><strong>processAlgorithm (必须)</strong> 定义算法执行逻辑。调用<code>processing.run</code>执行工具箱，最后返回输出与结果。</li></ul><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: rasterized_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: numfeatures</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>执行后结果如下所示：</p><p><img src="/qgis-cookbook/img/qgis/script-run.png" alt="script-run" data-fancybox="gallery"></p><h3 id="_3-alg装饰器" tabindex="-1">3. @alg装饰器 <a class="header-anchor" href="#_3-alg装饰器" aria-label="Permalink to &quot;3. @alg装饰器&quot;">​</a></h3><p>如下代码演示了如何使用<code>@alg装饰器</code>编写脚本文件。</p><div class="language-python vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis.processing </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> alg</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">from</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> qgis.core </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">import</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> QgsProject</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;bufferrasteralg&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲区计算并栅格化输出结果&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">     group</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;myscripts&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">group_label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;My scripts&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># &#39;INPUT&#39; is the recommended name for the main input parameter</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.input</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">SOURCE</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;输入矢量图层&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.input</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">RASTER_LAYER_DEST</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;栅格图层输出&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.input</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">VECTOR_LAYER_DEST</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲结果输出&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.input</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">DISTANCE</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFERDIST&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;缓冲距离&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.input</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">DISTANCE</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;CELLSIZE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;栅格单元格大小&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">default</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0.1</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># &#39;OUTPUT&#39; is the recommended name for the main output parameter</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">@alg.output</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">type</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">alg.</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">NUMBER</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">name</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">label</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;要素数量&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">)</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">def</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> bufferrasteralg</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(instance, parameters, context, feedback, inputs):</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    先进行缓冲区计算，在将结果转换为栅格展示。</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">    &quot;&quot;&quot;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    input_featuresource </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> instance.parameterAsSource(parameters,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                                     &#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, context)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    numfeatures </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> input_featuresource.featureCount()</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    bufferdist </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> instance.parameterAsDouble(parameters, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFERDIST&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                            context)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    rastercellsize </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> instance.parameterAsDouble(parameters, </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;CELLSIZE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                                context)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    buffer_result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;native:buffer&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                               {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;INPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;DISTANCE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: bufferdist,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;SEGMENTS&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;DISSOLVE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;END_CAP_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;JOIN_STYLE&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">0</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;MITER_LIMIT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">10</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                                },</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                               is_child_algorithm</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                               context</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">context,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                               feedback</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">feedback)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">    rasterized_result </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> processing.run(</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;qgis:rasterize&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                               {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;LAYER&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;EXTENT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;MAP_UNITS_PER_PIXEL&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: rastercellsize,</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">                                &#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: parameters[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">]</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">                               },</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                               is_child_algorithm</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">True</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">, </span><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">context</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">context,</span></span>
<span class="line"><span style="--shiki-light:#E36209;--shiki-dark:#FFAB70;">                               feedback</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">=</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">feedback)</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    if</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> feedback.isCanceled():</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">        return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {}</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">    return</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> {</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: rasterized_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;BUFFER_OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: buffer_result[</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;OUTPUT&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">],</span></span>
<span class="line"><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">            &#39;NUMBEROFFEATURES&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: numfeatures}</span></span></code></pre></div><h4 id="输入类型" tabindex="-1">输入类型 <a class="header-anchor" href="#输入类型" aria-label="Permalink to &quot;输入类型&quot;">​</a></h4><table class="colwidths-given longtable docutils align-default"><colgroup><col style="width:45%;"><col style="width:31%;"><col style="width:24%;"></colgroup><thead><tr class="row-odd"><th class="head"><p>Class</p></th><th class="head"><p>Alg constant</p></th><th class="head"><p>Description</p></th></tr></thead><tbody><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterAnnotationLayer.html#qgis.core.QgsProcessingParameterAnnotationLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterAnnotationLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.ANNOTATION_LAYER</span></code></p></td><td><p>An annotation layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterAuthConfig.html#qgis.core.QgsProcessingParameterAuthConfig" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterAuthConfig</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.AUTH_CFG</span></code></p></td><td><p>Allows users to select from available authentication configurations or create new authentication configurations</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterBand.html#qgis.core.QgsProcessingParameterBand" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterBand</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.BAND</span></code></p></td><td><p>A band of a raster layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterBoolean.html#qgis.core.QgsProcessingParameterBoolean" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterBoolean</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.BOOL</span></code></p></td><td><p>A boolean value</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterColor.html#qgis.core.QgsProcessingParameterColor" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterColor</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.COLOR</span></code></p></td><td><p>A color</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterCoordinateOperation.html#qgis.core.QgsProcessingParameterCoordinateOperation" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterCoordinateOperation</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.COORDINATE_OPERATION</span></code></p></td><td><p>A coordinate operation (for CRS transformations)</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterCrs.html#qgis.core.QgsProcessingParameterCrs" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterCrs</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.CRS</span></code></p></td><td><p>A Coordinate Reference System</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterDatabaseSchema.html#qgis.core.QgsProcessingParameterDatabaseSchema" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterDatabaseSchema</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.DATABASE_SCHEMA</span></code></p></td><td><p>A database schema</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterDatabaseTable.html#qgis.core.QgsProcessingParameterDatabaseTable" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterDatabaseTable</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.DATABASE_TABLE</span></code></p></td><td><p>A database table</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterDateTime.html#qgis.core.QgsProcessingParameterDateTime" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterDateTime</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.DATETIME</span></code></p></td><td><p>A datetime (or a pure date or time)</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterDistance.html#qgis.core.QgsProcessingParameterDistance" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterDistance</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.DISTANCE</span></code></p></td><td><p>A double numeric parameter for distance values</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterEnum.html#qgis.core.QgsProcessingParameterEnum" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterEnum</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.ENUM</span></code></p></td><td><p>An enumeration, allowing for selection from a set of predefined values</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterExpression.html#qgis.core.QgsProcessingParameterExpression" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterExpression</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.EXPRESSION</span></code></p></td><td><p>An expression</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterExtent.html#qgis.core.QgsProcessingParameterExtent" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterExtent</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.EXTENT</span></code></p></td><td><p>A spatial extent defined by xmin, xmax, ymin, ymax</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterField.html#qgis.core.QgsProcessingParameterField" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterField</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FIELD</span></code></p></td><td><p>A field in the attribute table of a vector layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterFile.html#qgis.core.QgsProcessingParameterFile" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterFile</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FILE</span></code></p></td><td><p>A filename of an existing file</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterFileDestination.html#qgis.core.QgsProcessingParameterFileDestination" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterFileDestination</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FILE_DEST</span></code></p></td><td><p>A filename for a newly created output file</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterFolderDestination.html#qgis.core.QgsProcessingParameterFolderDestination" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterFolderDestination</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FOLDER_DEST</span></code></p></td><td><p>A folder (destination folder)</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterGeometry.html#qgis.core.QgsProcessingParameterGeometry" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterGeometry</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.GEOMETRY</span></code></p></td><td><p>A geometry</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterNumber.html#qgis.core.QgsProcessingParameterNumber" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterNumber</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.INT</span></code></p></td><td><p>An integer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterLayout.html#qgis.core.QgsProcessingParameterLayout" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterLayout</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.LAYOUT</span></code></p></td><td><p>A layout</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterLayoutItem.html#qgis.core.QgsProcessingParameterLayoutItem" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterLayoutItem</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.LAYOUT_ITEM</span></code></p></td><td><p>A layout item</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterMapLayer.html#qgis.core.QgsProcessingParameterMapLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterMapLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MAPLAYER</span></code></p></td><td><p>A map layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterMapTheme.html#qgis.core.QgsProcessingParameterMapTheme" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterMapTheme</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MAP_THEME</span></code></p></td><td><p>A project map theme</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterMatrix.html#qgis.core.QgsProcessingParameterMatrix" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterMatrix</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MATRIX</span></code></p></td><td><p>A matrix</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterMeshLayer.html#qgis.core.QgsProcessingParameterMeshLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterMeshLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MESH_LAYER</span></code></p></td><td><p>A mesh layer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterMultipleLayers.html#qgis.core.QgsProcessingParameterMultipleLayers" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterMultipleLayers</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MULTILAYER</span></code></p></td><td><p>A set of layers</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterNumber.html#qgis.core.QgsProcessingParameterNumber" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterNumber</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.NUMBER</span></code></p></td><td><p>A numerical value</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterPoint.html#qgis.core.QgsProcessingParameterPoint" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterPoint</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.POINT</span></code></p></td><td><p>A point</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterPointCloudLayer.html#qgis.core.QgsProcessingParameterPointCloudLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterPointCloudLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.POINT_CLOUD_LAYER</span></code></p></td><td><p>A point cloud layer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterProviderConnection.html#qgis.core.QgsProcessingParameterProviderConnection" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterProviderConnection</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.PROVIDER_CONNECTION</span></code></p></td><td><p>An available connection for a database provider</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterRange.html#qgis.core.QgsProcessingParameterRange" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterRange</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.RANGE</span></code></p></td><td><p>A number range</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterRasterLayer.html#qgis.core.QgsProcessingParameterRasterLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterRasterLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.RASTER_LAYER</span></code></p></td><td><p>A raster layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterRasterDestination.html#qgis.core.QgsProcessingParameterRasterDestination" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterRasterDestination</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.RASTER_LAYER_DEST</span></code></p></td><td><p>A raster layer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterScale.html#qgis.core.QgsProcessingParameterScale" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterScale</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.SCALE</span></code></p></td><td><p>A map scale</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterFeatureSink.html#qgis.core.QgsProcessingParameterFeatureSink" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterFeatureSink</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.SINK</span></code></p></td><td><p>A feature sink</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterFeatureSource.html#qgis.core.QgsProcessingParameterFeatureSource" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterFeatureSource</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.SOURCE</span></code></p></td><td><p>A feature source</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterString.html#qgis.core.QgsProcessingParameterString" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterString</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.STRING</span></code></p></td><td><p>A text string</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterVectorLayer.html#qgis.core.QgsProcessingParameterVectorLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterVectorLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.VECTOR_LAYER</span></code></p></td><td><p>A vector layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingParameterVectorDestination.html#qgis.core.QgsProcessingParameterVectorDestination" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingParameterVectorDestination</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.VECTOR_LAYER_DEST</span></code></p></td><td><p>A vector layer</p></td></tr></tbody></table><h4 id="输出类型" tabindex="-1">输出类型 <a class="header-anchor" href="#输出类型" aria-label="Permalink to &quot;输出类型&quot;">​</a></h4><table class="colwidths-given longtable docutils align-default"><colgroup><col style="width:47%;"><col style="width:24%;"><col style="width:29%;"></colgroup><thead><tr class="row-odd"><th class="head"><p>Class</p></th><th class="head"><p>Alg constant</p></th><th class="head"><p>Description</p></th></tr></thead><tbody><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputBoolean.html#qgis.core.QgsProcessingOutputBoolean" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputBoolean</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.BOOL</span></code></p></td><td><p>A boolean value</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputNumber.html#qgis.core.QgsProcessingOutputNumber" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputNumber</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.DISTANCE</span></code></p></td><td><p>A double numeric parameter for distance values</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputFile.html#qgis.core.QgsProcessingOutputFile" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputFile</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FILE</span></code></p></td><td><p>A filename of an existing file</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputFolder.html#qgis.core.QgsProcessingOutputFolder" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputFolder</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.FOLDER</span></code></p></td><td><p>A folder</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputHtml.html#qgis.core.QgsProcessingOutputHtml" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputHtml</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.HTML</span></code></p></td><td><p>HTML</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputNumber.html#qgis.core.QgsProcessingOutputNumber" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputNumber</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.INT</span></code></p></td><td><p>A integer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputLayerDefinition.html#qgis.core.QgsProcessingOutputLayerDefinition" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputLayerDefinition</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.LAYERDEF</span></code></p></td><td><p>A layer definition</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputMapLayer.html#qgis.core.QgsProcessingOutputMapLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputMapLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MAPLAYER</span></code></p></td><td><p>A map layer</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputMultipleLayers.html#qgis.core.QgsProcessingOutputMultipleLayers" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputMultipleLayers</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.MULTILAYER</span></code></p></td><td><p>A set of layers</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputNumber.html#qgis.core.QgsProcessingOutputNumber" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputNumber</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.NUMBER</span></code></p></td><td><p>A numerical value</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputRasterLayer.html#qgis.core.QgsProcessingOutputRasterLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputRasterLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.RASTER_LAYER</span></code></p></td><td><p>A raster layer</p></td></tr><tr class="row-odd"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputString.html#qgis.core.QgsProcessingOutputString" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputString</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.STRING</span></code></p></td><td><p>A text string</p></td></tr><tr class="row-even"><td><p><a class="reference external" href="https://qgis.org/pyqgis/3.22/core/QgsProcessingOutputVectorLayer.html#qgis.core.QgsProcessingOutputVectorLayer" title="(in QGIS Python API v3.22)"><code class="xref py py-class docutils literal notranslate"><span class="pre">QgsProcessingOutputVectorLayer</span></code></a></p></td><td><p><code class="docutils literal notranslate"><span class="pre">alg.VECTOR_LAYER</span></code></p></td><td><p>A vector layer</p></td></tr></tbody></table></div></div></main><footer class="VPDocFooter" data-v-bb05d22a data-v-6b7c262b><!--[--><!--]--><!----><nav class="prev-next" data-v-6b7c262b><div class="pager" data-v-6b7c262b><a class="VPLink link pager-link prev" href="/qgis-cookbook/docs/senior/model.html" data-v-6b7c262b><!--[--><span class="desc" data-v-6b7c262b>←上一篇</span><span class="title" data-v-6b7c262b>2. 空间建模</span><!--]--></a></div><div class="pager" data-v-6b7c262b><!----></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><footer class="VPFooter has-sidebar" data-v-669ac9bc data-v-e2cf4f7a><div class="container" data-v-e2cf4f7a><!----><p class="copyright" data-v-e2cf4f7a>Copyright © 2023 LZUGIS</p></div></footer><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"docs_basic_index.md\":\"EB0gxyOj\",\"docs_basic_format.md\":\"htGaSmU5\",\"docs_basic_layer.md\":\"_kxckFIk\",\"docs_senior_toolbox.md\":\"BK3Sicf3\",\"index.md\":\"JoUA4piu\",\"docs_basic_edit.md\":\"irqswwQu\",\"docs_senior_model.md\":\"6fE6vE7W\",\"docs_basic_map.md\":\"UVwP91Xx\",\"docs_basic_style.md\":\"d4kb6_PA\",\"docs_basic_setup.md\":\"HLimTb9x\",\"docs_senior_dev.md\":\"-JHOtOsV\",\"docs_basic_raster.md\":\"GEJ8Z0B7\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"zh-CN\",\"dir\":\"ltr\",\"title\":\"QGIS使用教程\",\"description\":\"QGIS使用教程，从入门到进阶\",\"base\":\"/qgis-cookbook/\",\"head\":[],\"router\":{\"prefetchLinks\":true},\"appearance\":true,\"themeConfig\":{\"logo\":\"/logo.png\",\"siteTitle\":\"QGIS使用教程\",\"smoothScroll\":true,\"socialLinks\":[{\"icon\":{\"svg\":\"<svg t=\\\"1685841853530\\\" class=\\\"icon\\\" viewBox=\\\"0 0 1024 1024\\\" version=\\\"1.1\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" p-id=\\\"3800\\\" xmlns:xlink=\\\"http://www.w3.org/1999/xlink\\\" width=\\\"48\\\" height=\\\"48\\\"><path d=\\\"M352.814545 385.396364m-33.512727 0a33.512727 33.512727 0 1 0 67.025455 0 33.512727 33.512727 0 1 0-67.025455 0Z\\\" fill=\\\"#50B674\\\" p-id=\\\"3801\\\"></path><path d=\\\"M502.690909 384.465455m-33.512727 0a33.512727 33.512727 0 1 0 67.025454 0 33.512727 33.512727 0 1 0-67.025454 0Z\\\" fill=\\\"#50B674\\\" p-id=\\\"3802\\\"></path><path d=\\\"M576.232727 534.341818m-23.272727 0a23.272727 23.272727 0 1 0 46.545455 0 23.272727 23.272727 0 1 0-46.545455 0Z\\\" fill=\\\"#50B674\\\" p-id=\\\"3803\\\"></path><path d=\\\"M694.458182 536.203636m-23.272727 0a23.272727 23.272727 0 1 0 46.545454 0 23.272727 23.272727 0 1 0-46.545454 0Z\\\" fill=\\\"#50B674\\\" p-id=\\\"3804\\\"></path><path d=\\\"M512 0C229.003636 0 0 229.003636 0 512s229.003636 512 512 512 512-229.003636 512-512S794.996364 0 512 0z m-87.505455 630.225455c-26.996364 0-48.407273-5.585455-75.403636-11.17091l-75.403636 37.236364 21.410909-64.232727c-53.992727-37.236364-85.643636-85.643636-85.643637-145.221818 0-102.4 96.814545-182.458182 215.04-182.458182 105.192727 0 198.283636 64.232727 216.901819 150.807273-6.516364-0.930909-13.963636-0.930909-20.48-0.93091-102.4 0-182.458182 76.334545-182.458182 170.356364 0 15.825455 2.792727 30.72 6.516363 44.683636-7.447273 0-13.963636 0.930909-20.48 0.93091z m314.647273 75.403636l15.825455 53.992727-58.647273-32.581818c-21.410909 5.585455-42.821818 11.170909-64.232727 11.170909-102.4 0-182.458182-69.818182-182.458182-155.461818s80.058182-155.461818 182.458182-155.461818c96.814545 0 182.458182 69.818182 182.458182 155.461818 0 47.476364-31.650909 90.298182-75.403637 122.88z\\\" fill=\\\"#50B674\\\" p-id=\\\"3805\\\"></path></svg>\"},\"link\":\"https://lzugis.cn/\"},{\"icon\":{\"svg\":\"<svg t=\\\"1671270284061\\\" class=\\\"icon\\\" viewBox=\\\"0 0 1024 1024\\\" version=\\\"1.1\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" p-id=\\\"1920\\\" width=\\\"64\\\" height=\\\"64\\\"><path d=\\\"M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512z m259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z\\\" fill=\\\"#C71D23\\\" p-id=\\\"1921\\\"></path></svg>\"},\"link\":\"https://gitee.com/lzugis15\"},{\"icon\":{\"svg\":\"<svg t=\\\"1671270414569\\\" class=\\\"icon\\\" viewBox=\\\"0 0 1024 1024\\\" version=\\\"1.1\\\" xmlns=\\\"http://www.w3.org/2000/svg\\\" p-id=\\\"2135\\\" width=\\\"64\\\" height=\\\"64\\\"><path d=\\\"M512 0c282.784 0 512 229.216 512 512s-229.216 512-512 512S0 794.784 0 512 229.216 0 512 0z m189.952 752l11.2-108.224c-31.904 9.536-100.928 16.128-147.712 16.128-134.464 0-205.728-47.296-195.328-146.304 11.584-110.688 113.152-145.696 232.64-145.696 54.784 0 122.432 8.8 151.296 18.336L768 272.704C724.544 262.24 678.272 256 599.584 256c-203.2 0-388.704 94.88-406.4 263.488C178.336 660.96 303.584 768 535.616 768c80.672 0 138.464-6.432 166.336-16z\\\" fill=\\\"#CE000D\\\" p-id=\\\"2136\\\"></path></svg>\"},\"link\":\"https://blog.csdn.net/GISShiXiSheng\"}],\"nav\":[{\"text\":\"GIS基础\",\"link\":\"https://lzugis15.gitee.io/qgis-cookbook/img/GIS基础.pdf\"},{\"text\":\"QGIS基础操作\",\"link\":\"/docs/basic/\"},{\"text\":\"QGIS进阶操作\",\"link\":\"/docs/senior/toolbox\"}],\"sidebar\":{\"/docs/basic/\":[{\"text\":\"1. 概览\",\"link\":\"/docs/basic/\"},{\"text\":\"2. 安装与界面简介\",\"link\":\"/docs/basic/setup\"},{\"text\":\"3. 图层与数据添加\",\"link\":\"/docs/basic/layer\"},{\"text\":\"4. 图层导出与格式转换\",\"link\":\"/docs/basic/format\"},{\"text\":\"5. 图层创建与编辑\",\"link\":\"/docs/basic/edit\"},{\"text\":\"6. 样式操作与样式设置\",\"link\":\"/docs/basic/style\"},{\"text\":\"7. 地图导出与制图\",\"link\":\"/docs/basic/map\"},{\"text\":\"8. 栅格数据操作\",\"link\":\"/docs/basic/raster\"}],\"/docs/senior/\":[{\"text\":\"1. 工具箱使用\",\"link\":\"/docs/senior/toolbox\"},{\"text\":\"2. 空间建模\",\"link\":\"/docs/senior/model\"},{\"text\":\"3. QGIS二次开发\",\"link\":\"/docs/senior/dev\"}]},\"outline\":\"deep\",\"outlineTitle\":\"章节导航\",\"docFooter\":{\"prev\":\"←上一篇\",\"next\":\"下一篇→\"},\"lastUpdatedText\":\"上次更新时间\",\"footer\":{\"message\":\"\",\"copyright\":\"Copyright © 2023 LZUGIS\"}},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}");</script>
    
  </body>
</html>